#!/bin/bash

if [ $# -eq 0 ]; then
	echo "run - Compile and Run C/C++/Java/Ruby source"
	echo "usage: run FILENAME args ..."
	exit -1
fi

SRC=$1
NAME=

shift

case "$SRC" in
	*.java)
		NAME=${SRC%.java}
		javac $SRC
		if [ $? -eq 0 ]; then java $NAME $*; fi
		;;
	*.bas)
		NAME=${SRC%.bas}
		fbc $SRC -x $NAME
		if [ $? -eq 0 ]; then ./$NAME $*; fi
		;;
	*.c)
		NAME=${SRC%.c}
		gcc $SRC -g -o $NAME
		if [ $? -eq 0 ]; then ./$NAME $*; fi
		;;
	*.cpp)
		NAME=${SRC%.cpp}
		g++ $SRC -g -o $NAME
		if [ $? -eq 0 ]; then ./$NAME $*; fi
		;;
	*.cs)
		NAME=${SRC%.cs}
		dmcs $SRC
		if [ $? -eq 0 ]; then mono $NAME.exe $*; fi
		;;
	*.rb)
		ruby $SRC $*
		;;
esac

